package com.example.sourcecodelearning.controller;

import com.example.framework.common.pojo.R;
import com.example.framework.mq.kafka.core.util.KafkaProducerUtils;
import com.example.framework.mq.rocketmq.core.util.RocketMQProducerUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.rocketmq.client.producer.SendResult;
import org.springframework.web.bind.annotation.*;

@Tag(name = "MQ服务")
@RestController
public class MQController {

    @Operation(summary = "发送RocketMQ消息")
    @GetMapping("/sendByRocketMQ")
    public R<SendResult> sendByRocketMQ(@RequestParam String topic,
                                        @RequestParam(required = false, defaultValue = "tag") String tag,
                                        @RequestParam String message) {
        SendResult sendResult = RocketMQProducerUtils.sendMessage(topic, tag, message);
        return R.success(sendResult);
    }

    @Operation(summary = "发送kafka消息")
    @PostMapping("/sendByKafka")
    public R<?> sendMessage(@RequestParam String topic, @RequestBody Object msgBody) {
        KafkaProducerUtils.sendMessage(topic, msgBody);
        return R.success();
    }

}
